package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketStorage;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * @author gatsby
 * @since 2022/10/12 09:20
 */
@RestController
@RequestMapping("admin/storage")
public class AdminStorageController {

    @Autowired
    AdminStorageService adminStorageService;

    @RequestMapping("create")
    public BaseRespVo uploadFile(MultipartFile file) throws IOException {

        MarketStorage marketStorage = adminStorageService.uploadFile(file);

        return BaseRespVo.ok(marketStorage, "成功");

    }

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo,String key,String name){
        CommonData<MarketStorage> commonData=adminStorageService.queryStorageLimit(basePageInfo,key,name);
        return BaseRespVo.ok(commonData,"成功");
    }

    /**
     * 更新对象的业务逻辑
 * @param marketStorage
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @author gatsby
     * @since 2022/10/12 20:38
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketStorage marketStorage){
        MarketStorage marketStorage1=adminStorageService.updateName(marketStorage);
        return BaseRespVo.ok(marketStorage1,"成功");
    }

    /**
     * 删除对象的业务逻辑
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @author gatsby
     * @since 2022/10/12 20:38
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketStorage marketStorage){
        adminStorageService.delete(marketStorage);
        return BaseRespVo.ok("成功");
    }

}
